(library (debug)
  (export debug-peek
          pretty-peek)

  (import
   (except (rnrs base)
           let-values
           map
           error
           vector-map)
   (only (guile)
         lambda* λ
         simple-format
         current-output-port
         call-with-output-string)
   (ice-9 pretty-print))


  (define debug-peek
    (lambda* (sth #:optional (message ""))
      (let ([as-string
             (call-with-output-string
               (λ (port)
                 (simple-format port "~a" sth)))])
        (simple-format (current-output-port)
                       "~a~a\n"
                       message
                       as-string)
        sth)))


  (define pretty-peek
    (lambda* (thing
              #:optional (port (current-output-port))
              #:key
              (width 80)
              (max-expr-width 80)
              (display? #t)
              (per-line-prefix "")
              (select (λ (thing) thing)))
      (pretty-print (select thing)
                    #:port port
                    #:width width
                    #:max-expr-width max-expr-width
                    #:display? display?
                    #:per-line-prefix per-line-prefix)
      thing)))
